﻿#pragma once

// ASIO Library
// 如需使用请定义请定义 MY_USE_ASIO 或者 MY_USE_ASIO_98

#ifdef _MSC_VER
	#pragma warning(push)
	#pragma warning(disable:4996)	// 'function': was declared deprecated
	//#pragma warning(disable:4819)	// The file contains a character that cannot be represented in the current code page (number). 
	//#pragma warning(disable:4701)	// potentially uninitialized local variable 'result' used
	#pragma warning(disable:4100)	// 'identifier': unreferenced formal parameter
	#pragma warning(disable:4101)	// 'identifier': unreferenced local variable
	//#pragma warning(disable:4245)	// 'initializing' : conversion from 'type2' to 'type2', signed/unsigned mismatch
	//#pragma warning(disable:4127)	// conditional expression is constant
	//#pragma warning(disable:4512)	// assignment operator could not be generated
	//#pragma warning(disable:4510)	//'boost::array<T,N>' : default constructor could not be generated
	//#pragma warning(disable:4610)	// class 'boost::array<T,N>' can never be instantiated - user defined constructor required
	//#pragma warning(disable:4005)	// warning C4005: 'FD_SETSIZE' : macro redefinition
#endif

#ifdef MY_USE_ASIO
	
	// 暂时改变_WIN32_WINNT定义到Win2000以获得最佳兼容性
	#ifdef _WIN32_WINNT		// 允许使用 Windows NT 4 或更高版本的特定功能。
		#if _WIN32_WINNT == 0x0400		// Windows NT 4.0
			#include <boost/asio.hpp>

		#elif _WIN32_WINNT == 0x0500	// Windows 2000
			#include <boost/asio.hpp>

		#elif _WIN32_WINNT == 0x0501	// Windows XP
			#undef _WIN32_WINNT
			#define _WIN32_WINNT 0x0500
			#include <boost/asio.hpp>
			#undef _WIN32_WINNT
			#define _WIN32_WINNT 0x0501

		#elif _WIN32_WINNT == 0x0502	// Windows 2003
			#undef _WIN32_WINNT
			#define _WIN32_WINNT 0x0500
			#include <boost/asio.hpp>
			#undef _WIN32_WINNT
			#define _WIN32_WINNT 0x0502

		#elif _WIN32_WINNT == 0x0600	// Windows Vista
			#undef _WIN32_WINNT
			#define _WIN32_WINNT 0x0500
			#include <boost/asio.hpp>
			#undef _WIN32_WINNT
			#define _WIN32_WINNT 0x0600

		#elif _WIN32_WINNT == 0x0601	// Windows 7
			#undef _WIN32_WINNT
			#define _WIN32_WINNT 0x0500
			#include <boost/asio.hpp>
			#undef _WIN32_WINNT
			#define _WIN32_WINNT 0x0600

		#else
			#pragma  message("unknown _WIN32_WINNT \n")
			#pragma warning( error : 1 )
		#endif

	#elif defined(_WIN32_WCE)			// Win CE

		#undef _WIN32_WINNT
		#define _WIN32_WINNT 0x0500
		#define ASIO_DISABLE_IOCP
		#define BOOST_NO_STD_MESSAGES

		// define it for WinCE
		#ifndef TLS_OUT_OF_INDEXES
		#define TLS_OUT_OF_INDEXES    0xFFFFFFFF
		#endif

		// copied from boost::thread::thread.cpp
		// Windows CE doesn't define _beginthreadex
		struct ThreadProxyData
		{
			typedef unsigned (__stdcall* func)(void*);
			func start_address_;
			void* arglist_;
			ThreadProxyData(func start_address,void* arglist) : start_address_(start_address), arglist_(arglist) {}
		};

		inline DWORD WINAPI ThreadProxy(LPVOID args)
		{
			ThreadProxyData* data=reinterpret_cast<ThreadProxyData*>(args);
			DWORD ret=data->start_address_(data->arglist_);
			delete data;
			return ret;
		}

		inline unsigned _beginthreadex(void* security, unsigned stack_size, unsigned (__stdcall* start_address)(void*),
									   void* arglist, unsigned initflag,unsigned* thrdaddr)
		{
			DWORD threadID;
			HANDLE hthread=CreateThread(static_cast<LPSECURITY_ATTRIBUTES>(security),stack_size,ThreadProxy,
				new ThreadProxyData(start_address,arglist),initflag,&threadID);
			if (hthread!=0)
				*thrdaddr=threadID;
			return reinterpret_cast<unsigned>(hthread);
		}

		#include <boost/asio.hpp>
		#undef _WIN32_WINNT

	#endif

#elif defined MY_USE_ASIO_98

	// 暂时改变_WIN32_WINNT定义到Win2000以获得最佳兼容性
	#ifdef _WIN32_WINNT		// 允许使用 Windows NT 4 或更高版本的特定功能。
		#if _WIN32_WINNT == 0x0400		// Windows NT 4.0
			#undef _WIN32_WINNT
			#include <boost/asio.hpp>
			#define _WIN32_WINNT 0x0400

		#elif _WIN32_WINNT == 0x0500	// Windows 2000
			#undef _WIN32_WINNT
			#include <boost/asio.hpp>
			#define _WIN32_WINNT 0x0500

		#elif _WIN32_WINNT == 0x0501	// Windows XP
			#undef _WIN32_WINNT
			#include <boost/asio.hpp>
			#define _WIN32_WINNT 0x0501

		#elif _WIN32_WINNT == 0x0502	// Windows 2003
			#undef _WIN32_WINNT
			#include <boost/asio.hpp>
			#define _WIN32_WINNT 0x0502

		#elif _WIN32_WINNT == 0x0600	// Windows Vista
			#undef _WIN32_WINNT
			#include <boost/asio.hpp>
			#define _WIN32_WINNT 0x0600

		#elif _WIN32_WINNT == 0x0601	// Windows 7
			#undef _WIN32_WINNT
			#include <boost/asio.hpp>
			#define _WIN32_WINNT 0x0600

		#else
			#pragma  message("unknown _WIN32_WINNT \n")
			#pragma warning( error : 1 )
		#endif
	#endif

#elif defined MY_USE_ASIO_LINUX

	#include <boost/asio.hpp>

#endif

#ifdef _MSC_VER
	#pragma warning(pop)
#endif
